package com.xbongbong.saas.enums;

import com.xbongbong.i18n.util.I18nMessageUtil;
import com.xbongbong.sys.enums.CompanyStructTypeEnum;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
 * 业绩目标类型
 *
 * @author hongxiao
 * @date 2019-01-26 10:48
 * @since v1.0
 */
@Getter
public enum PerformanceTypeEnum {

    // 业绩目标类型
    PERFORMANCE_USER("performanceUser", CompanyStructTypeEnum.USER.getCode(), "enum.performanceType.titleName.performance_user", "enum.performanceType.excelName.performance_user"),
    PERFORMANCE_DEP("performanceDep", CompanyStructTypeEnum.DEPARTMENT.getCode(), "enum.performanceType.titleName.performance_dep", "enum.performanceType.excelName.performance_dep"),
    UNKNOWN("unknown", CompanyStructTypeEnum.UNKNOWN.getCode(), "enum.performanceType.titleName.unknown", "enum.performanceType.excelName.unknown");

    private String type;
    private int objectiveType;
    private String titleName;
    private String excelName;

    PerformanceTypeEnum(String type, int objectiveType, String titleName, String excelName) {
        this.type = type;
        this.objectiveType = objectiveType;
        this.titleName = titleName;
        this.excelName = excelName;
    }

    public static PerformanceTypeEnum getByType(String type) {
        for (PerformanceTypeEnum cache : values()) {
            if (Objects.equals(type, cache.getType())) {
                return cache;
            }
        }
        return UNKNOWN;
    }

    public static List<PerformanceTypeEnum> getAllEnum() {
        List<PerformanceTypeEnum> list = new ArrayList<>();
        for (PerformanceTypeEnum cache : values()) {
            if (cache == UNKNOWN) {
                continue;
            }
            list.add(cache);
        }
        return list;
    }

    public String getTitleName() {
        return I18nMessageUtil.getMessage(titleName);
    }

    public String getExcelName() {
        return I18nMessageUtil.getMessage(excelName);
    }
}
